package siga.banco;

import java.sql.*;
import siga.visao.verErros;

public class unimestre {
    public static Connection banco = null;
    public static Statement stm = null;
    public static ResultSet rs = null;
    public static PreparedStatement ps = null;
    public static String AutoIncRS;

    private static String drive = "jdbc:mysql://192.168.0.253:3306/unimestre";
//    private static String drive = "jdbc:mysql://201.35.207.198:4444/unimestre";
    private static String db_user = "academico";
    private static String db_pw = "UniMestreProSurf";

    public static void main (String args[]){
        //Conexao();
        //FechaConexao();
    }

    public static void Conexao(){
        try{
            Class.forName("com.mysql.jdbc.Driver");
            banco = DriverManager.getConnection(drive,db_user,db_pw);
            stm = banco.createStatement();
        } catch (ClassNotFoundException ex) {
            verErros.setErro("(Conexao): "+ex.getMessage());
        }catch(SQLException ex){
            verErros.setErro("(Conexao): "+ex.getMessage());
        }
    }

    public static void FechaConexao(){
        try{
            if(banco.isClosed()){
              banco.close();
            }
        }catch(SQLException ex){
            verErros.setErro("(FechaConexao): "+ex.getMessage());
        }
    }

    public static void Query(String sql){
        try {
            Conexao();
            rs = stm.executeQuery(sql);
            FechaConexao();
        } catch (SQLException ex) {
            verErros.setErro("(Query): "+ex.getMessage());
        }
    }

    public static void QueryGT(String sql){
        try {
            //Conexao();
            rs = stm.executeQuery(sql);
            //FechaConexao();
        } catch (SQLException ex) {
            verErros.setErro("(Query): "+ex.getMessage());
        }
    }

    public static ResultSet res(){
        return rs;
    }

}